package com.fs.api.enumeration;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fs.common.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import static com.fs.common.enumeration.BusinessExceptionEnum.PARAM_ERROR;

@Getter
@AllArgsConstructor
public enum EmploymentStatus {
    IN_OFFICE("在职"),
    OUT_OFFICE("离职");

    @EnumValue  // MybatisPlus注解，将枚举值映射为数据库中的值
    @JsonValue  // JSON序列化时使用的值
    private final String value;

    // 根据值获取枚举对象
    public static EmploymentStatus fromValue(String value) {
        for (EmploymentStatus employmentStatus : EmploymentStatus.values()) {
            if (employmentStatus.getValue().equals(value)) {
                return employmentStatus;
            }
        }
        throw new BusinessException(PARAM_ERROR);
    }
}
